Relational and object-relational database management systems store information in tables in a database. To retrieve data, queries that request data are submitted to a database server, which computes the queries and returns the data requested. Query statements submitted to the database server should conform to the syntactical rules of a particular query language. One popular query language, Structured Query Language (SQL), provides users a variety of ways to specify information to be retrieved.
A query submitted to a database server is evaluated by a query optimizer. Based on the evaluation, the query optimizer generates an execution plan that is optimized for efficient execution. The optimized execution plan may be based on a rewrite of the query into a semantically equivalent but more efficient form.
SQL supports DISTINCT clauses, which are used to return distinct values, and GROUP BY clauses, which are used in combination with aggregate functions to group result-sets by one or more columns.
Described herein are techniques for rewriting queries that contain GROUP BY and DISTINCT clauses so that such queries may be executed more efficiently.
The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in this section.